#include "SimulatorBase.h"

SimulatorBase::SimulatorBase()
{
	cout<<"**** You should not be able to call me!!!\n"; 
	throw;
};
SimulatorBase::SimulatorBase(double maxTime,double timeStep)
{
	this->m_timeStep = timeStep;
	this->m_maxTime = maxTime;
	printSimCreateInfo();
};
void SimulatorBase::printSimCreateInfo()
{
	cout<<"****"<<endl;
	cout<<"Simulator is created"<<endl;
	cout<<"Simulator info:"<<endl;
	cout<<"\tMax_Time: "<<m_maxTime<<endl;
	cout<<"\tTime_Step: "<<m_timeStep<<endl;
};

void SimulatorBase::printSimDestructorInfo()
{
	cout<<"****"<<endl;
	cout<<"That's the end of the simulator life :("<<endl;
	cout<<"See you soon"<<endl;
	cout<<"****"<<endl;
};
bool SimulatorBase::RegisterEntity(AbstractEntity* entity){
	const bool result = (m_EntityMap.end()==m_EntityMap.find(entity->GetName()));
	if ( result){
		m_EntityMap[entity->GetName()] = entity;
		m_Signal_Dispatcher_Entity.connect(boost::bind(&AbstractEntity::operator(),entity, _1));
		cout << "Simulator: Registering "<< entity->GetName()<< " was successful." << endl;
	}
	else{
		cout << "Simulator: Registering "<< entity->GetName() << " was not successful -> "<< entity->GetName() <<" is alreay registered " << endl;
	}

	return result;
}

void SimulatorBase::SendSignal(double time){
	m_Signal_Dispatcher_Entity(time);
}

void SimulatorBase::Run(){

	for (double t=0;t<m_maxTime; t +=m_timeStep){
		this->SendSignal(t);
	}

}

SimulatorBase::~SimulatorBase()
{
	printSimDestructorInfo();
};
